from core.support import set_cutscene
from core.item import Item
from core.action import Action
from items.detonator import Detonator

class Keys(Item):
    def __init__(self):
        Item.__init__(self, "keys")    # do basic initialization for every item
        
        # build list of actions
        self.add_action(UnlockFailSafe)
    
    def get_description(self):
        return "Book (key inside)"

# define actions for this item

class UnlockFailSafe(Action):
    def __init__(self):
        Action.__init__(self, "unlock_failsafe")    # do basic initialization for every action
    
    # return description of action (used in label on webpage)
    def get_description(self):
        return "Use Key"
    
    # return http method to use when user clicks on this action
    # use "get" if just moving to another room.  if changing something
    # like the state of an inventory item or room then use "post"
    def get_method(self):
        return "post"
    
    # only works in basement. add cutscene
    def do_action(self,game,room,request):
        if room.get_id() == 'computerroom':
            if room.failsafe_locked:
                
                set_cutscene("You unlock the trapdoor. Almost immediately, an apocalyptic feeling begins to run down your spine.")
                room.failsafe_locked = False
                room.add_item(Detonator())
                
            else:
                set_cutscene("The trapdoor is already unlocked.")
        else:
            set_cutscene("There is nothing to unlock. Check the other rooms.")
        return